package com.hongning.railway.ui.main.mine.score;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.AppViewModelFactory;
import com.hongning.railway.app.Constant;
import com.hongning.railway.databinding.FragmentRankTypeBinding;
import com.hongning.railway.entity.resbean.ResScoreRankInfo;
import com.hongning.railway.ui.adapter.RankAdapter;

import me.goldze.mvvmhabit.base.BaseFragment;

public class RankTypeFragment extends BaseFragment<FragmentRankTypeBinding, RankTypeFragmentViewModel> {

    private ResScoreRankInfo mResScoreRankInfo;
    private int type;
    public static RankTypeFragment newInstance(ResScoreRankInfo resScoreRankInfo,int type) {
        Bundle args = new Bundle();
        args.putParcelable(Constant.EXTRA_DATA,resScoreRankInfo);
        args.putInt(Constant.EXTRA_INT,type);
        RankTypeFragment fragment = new RankTypeFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_rank_type;
    }

    @Override
    public void initParam() {
        super.initParam();
        mResScoreRankInfo = getArguments().getParcelable(Constant.EXTRA_DATA);
        type = getArguments().getInt(Constant.EXTRA_INT);
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        binding.rvContent.setAdapter(new RankAdapter());
        if (type == 1){
            //总分排行
            viewModel.loaddata(null);
            viewModel.setHeadInfo(mResScoreRankInfo);
        }else if (type ==2){
            //红宁积分总排行 需要修改
            viewModel.loadHnData(null);
            viewModel.setHeadInfo(mResScoreRankInfo);
        }else if (type ==3){
            //支部积分排行
            viewModel.loadzhibudata(null);
            viewModel.setzhibuHeadInfo(mResScoreRankInfo);
        }else if (type==4){
            viewModel.setzhibuHeadInfo(mResScoreRankInfo);
            viewModel.loadzhibuHndata(null);
        }

    }

    @Override
    public RankTypeFragmentViewModel initViewModel() {
        AppViewModelFactory appViewModelFactory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this,appViewModelFactory).get(RankTypeFragmentViewModel.class);
    }

    public void filterbydata(long millseconds) {
        if (type == 1){
            //总分排行
            viewModel.loaddata(String.valueOf(millseconds));
            viewModel.setHeadInfo(mResScoreRankInfo);
        }else if (type ==2){
            //红宁积分总排行 需要修改
            viewModel.loadHnData(String.valueOf(millseconds));
            viewModel.setHeadInfo(mResScoreRankInfo);
        }else if (type ==3){
            //支部积分排行
            viewModel.loadzhibudata(String.valueOf(millseconds));
            viewModel.setzhibuHeadInfo(mResScoreRankInfo);
        }else if (type==4){
            viewModel.setzhibuHeadInfo(mResScoreRankInfo);
            viewModel.loadzhibuHndata(String.valueOf(millseconds));
        }
    }
}
